package org.kealinghornets.jchuah.myapplication;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.GridLayoutAnimationController;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


public class MyActivity2 extends Activity {
        int numCleared = 0;
    public void onNonYellowButtonPush(final View myView) {
        Log.d("Kealinghornets.myApp2", "Wrong");

        Toast toast = Toast.makeText(this, "Disloyalty! 50 points from Hufflepuff! To gain 50 points instead of losing them, click on the Hufflepuff color.", Toast.LENGTH_SHORT);
        LinearLayout layout = (LinearLayout) toast.getView();
        if (layout.getChildCount() > 0) {
            TextView tv = (TextView) layout.getChildAt(0);
            tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);

        }
        Animation fade_out_animation = AnimationUtils.loadAnimation(this, R.anim.fade_out);
        fade_out_animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                myView.setEnabled(false);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                myView.setEnabled(true);
                myView.setAlpha(0);


                myView.clearAnimation();

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        toast.show();
        if (myView.getAlpha() == 1) {
            myView.startAnimation(fade_out_animation);
            numCleared = numCleared + 1;
        } else {
            myView.setAlpha(1);


            numCleared = numCleared - 1;
        }
        String buttonName = getResources().getResourceEntryName(myView.getId());
        int buttonRow = Integer.parseInt(buttonName.charAt(5) + "");
        int buttonColumn = Integer.parseInt(buttonName.charAt(6) + "");
        Log.d("button", "row: " + buttonRow + " column: " + buttonColumn);


        if (numCleared == 10) {

        }

    }

    public void onYellowButtonPush(View myView) {
        Log.d("Kealinghornets.myApp2", "Right");

        Toast toast = Toast.makeText(this, "Congratulations! Welcome to Hufflepuff. You have earned 50 house points.", Toast.LENGTH_LONG);
        LinearLayout layout = (LinearLayout) toast.getView();
        if (layout.getChildCount() > 0) {
            TextView tv = (TextView) layout.getChildAt(0);
            tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
        startActivity(new Intent(this, MyActivity3.class));
        }

        toast.show();


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_activity2);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my_activity2, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
